In [1]:
%pylab inline
In [2]:
from IPython.display import IFrame
IFrame('http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.morphology.distance_transform_edt.html',
width='100%', height=400)
Out[2]:
In [3]:
import numpy as np
from scipy.ndimage.morphology import distance_transform_edt
In [4]:
a = np.array(([0,1,1,1,1],
[0,0,1,1,1],
[0,1,1,1,1],
[0,1,1,1,0],
[0,1,1,0,0]))
dist, ind = distance_transform_edt(a, sampling=[2, 0.11], return_indices=True)
dist
Out[4]:
In [5]:
ind
Out[5]:
In [6]:
n = 200
a = np.random.randint(low=0, high=2, size=(n,n,n))
%timeit dist = distance_transform_edt(a, sampling=[2.001, 0.11, 0.73])
In [7]:
a = np.random.rand(n,n,n)
a[a < 0.5] = 0
a[a >= 0.5] = 1
%timeit dist = distance_transform_edt(a, sampling=[2.001, 0.11, 0.73])
In [8]:
a = np.random.rand(n,n,n)
a[a < 0.5] = 0
a[a >= 0.5] = 1
%timeit dist, ind = distance_transform_edt(a, sampling=[2.001, 0.11, 0.73], return_indices=True)